/*=========================================================================================== 	* Date: Sept 2018
	* Purpose: Create NAPP sample restricted to London with variables that can be matched with locations on historical map
	* DATASETS Used:
		- "$NAPP/napp_00002.dta" : NAPP GB1881 with addresses (this data is not provided because one needs to apply to the North Atlantic Population Project )
	* DATASETS Created: 
		- "$NAPP/NAPP_London3V1.dta"
===========================================================================================*/

cd "/Users/`c(username)'/Dropbox/NetworkParish2016/Occupational_Choice/Submission/ReStat_R&R/Codes/A_CREATING_SAMPLE"
gl NAPP "/Users/`c(username)'/Dropbox/NetworkParish2016/Occupational_Choice/Submission/ReStat_R&R/Codes/NAPP"
// 1. Restrict to London 

use "$NAPPRaw/napp_00002.dta", clear
keep if GB81A_PARIDGB<301

// 2. Substract the "GB81A_" before each variable

foreach var of varlist GB81A*{
	local newname = substr("`var'", 7, .)
	rename `var' `newname'
}

// 3. To transform the label of parishgb (parishgb_lbl) from lower to uppercase. 

labvalch3 PARIDGB, upper

// 4. Differences in the name of parishes

labvalch3, subst("BRIDEWELL" "BRIDEWELL PRECINCT")
labvalch3, subst("CHRISTCHURCH NEWGATE STREET" "CHRISTCHURCH (NEWGATE)")
labvalch3, subst("CHRISTCHURCH SOUTHWARK" "CHRISTCHURCH, SOUTHWARK")
labvalch3, subst("SERJEANTS INN FLEET STREET" "SERJEANTS INN")
labvalch3, subst("ST OLAVE SOUTHWARK" "SOUTHWARK ST. OLAVE")
labvalch3, subst("ST THOMAS SOUTHWARK" "SOUTHWARK ST. THOMAS")
labvalch3, subst("ST ALPHAGE SION COLLEGE" "ST ALPHAGE")
labvalch3, subst("ST ANN BLACKFRIARS" "ST ANNE BLACKFRIARS")
labvalch3, subst("ST AUGUSTINE WATLING STREET" "ST AUGUSTINE (WATLING STREET)")
labvalch3, subst("ST BARTHOLOMEW BY THE ROYAL EXCHANGE" "ST BARTHOLOMEW BY THE EXCHANGE")
labvalch3, subst("ST BENET GRACECHURCH STREET" "ST BENET GRACECHURCH")
labvalch3, subst("ST CHRISTOPHER-LE-STOCK" "ST CHRISTOPHER LE STOCKS")
labvalch3, subst("ST JOHN THE BAPTIST WALBROOK" "ST JOHN THE BAPTIST")
labvalch3, subst("ST MARY-LE-BOW" "ST MARY LE BOW")
labvalch3, subst("ST MARY WOOLCHURCH-HAW" "ST MARY WOOLCHURCH")
labvalch3, subst("ST MICHAEL-LE-QUERN" "ST MICHAEL LE QUERNE")
labvalch3, subst("ST NICHOLAS ACONS" "ST NICHOLAS ACON")
labvalch3, subst("ST OLAVE HART STREET WITH ST NICHOLAS I" "ST OLAVE HART STREET")
labvalch3, subst("ST PETER-LE-POER" "ST PETER LE POOR")
labvalch3, subst("ST PETER NEAR PAULS WHARF" "ST PETHER PAULS WHARF")
labvalch3, subst("ST SWITHIN LONDON STONE" "ST SWITHIN")
labvalch3, subst("ST THOMAS APOSTLE" "ST THOMAS THE APOSTLE")
labvalch3, subst("ST VEDAST FOSTER LANE" "ST VEDAST")
labvalch3, subst("ST ANDREW HOLBORN ABOVE THE BARS AND ST" "ST. ANDREW HOLBORN ABOVE THE BARS WITH")
labvalch3, subst("ST ANDREW HOLBORN BELOW THE BARS" "ST. ANDREW HOLBORN BELOW THE BARS")
labvalch3, subst("ST BOTOLPH WITHOUT BISHOPSGATE" "ST. BOTOLPH WITHOUT BISHOPSGATE")
labvalch3, subst("ST GEORGE HANOVER SQUARE" "ST. GEORGE HANOVER SQUARE")
labvalch3, subst("ST GEORGE IN THE EAST" "ST. GEORGE IN THE EAST")
labvalch3, subst("ST GEORGE THE MARTYR SOUTHWARK" "ST. GEORGE THE MARTYR")
labvalch3, subst("ST GILES IN THE FIELDS AND ST GEORGE BL" "ST. GILES IN THE FIELDS AND ST. GEORGE")
labvalch3, subst("ST GILES WITHOUT CRIPPLEGATE" "ST. GILES WITHOUT CRIPPLEGATE")
labvalch3, subst("ST JAMES WESTMINSTER" "ST. JAMES WESTMINSTER")
labvalch3, subst("HORSLEYDOWN" "ST. JOHN HORSLEYDOWN")
labvalch3, subst("ST KATHERINE BY THE TOWER" "ST. KATHERINE BY THE TOWER")
labvalch3, subst("ST LUKE" "ST. LUKE")
labvalch3, subst("ST MARGARET AND ST JOHN THE EVANGELIST" "ST. MARGARET AND ST. JOHN")
labvalch3, subst("ST MARTIN IN THE FIELDS" "ST. MARTIN IN THE FIELDS")
labvalch3, subst("ST MARY-LE-STRAND" "ST MARY LE STRAND")
labvalch3, subst("ST NICHOLAS DEPTFORD" "ST. NICHOLAS DEPTFORD")
labvalch3, subst("ST PAUL DEPTFORD" "ST. PAUL DEPTFORD")
labvalch3, subst("ST SAVIOUR SOUTHWARK" "ST. SAVIOUR SOUTHWARK")
labvalch3, subst("ST SEPULCHRE" "ST. SEPULCHRE")
labvalch3, subst("WHITEFRIARS" "WHITEFRIARS PRECINCT")
labvalch3, subst("SAVOY" "LIBERTY OF THE SAVOY")
labvalch3, subst("ALLHALLOWS HONEY LANE" "ALL HALLOWS HONEY LANE")
labvalch3, subst("ST. GEORGE HANOVER SQUARE" "ST GEORGE HANOVER SQUARE")
labvalch3, subst("ST. JAMES WESTMINSTER" "ST JAMES WESTMINSTER")
labvalch3, subst("ST. GILES IN THE FIELDS AND ST. GEORGEO" "ST GILES IN THE FIELDS")
labvalch3, subst("ST. MARTIN IN THE FIELDS" "ST MARTIN IN THE FIELDS")
labvalch3, subst("LINCOLNS INN" "LINCOLN'S INN")
labvalch3, subst("GRAYS INN" "GRAY'S INN")
labvalch3, subst("FURNIVALS INN" "FURNIVAL'S INN")
labvalch3, subst("ST. SEPULCHRE" "ST SEPULCHRE")
labvalch3, subst("CHARTERHOUSE" "CHARTER HOUSE")
labvalch3, subst("ST BOTOLPH WITHOUT ALDGATE" "ST BOTOLPH ALDGATE")
labvalch3, subst("ST. BOTOLPH WITHOUT BISHOPSGATE" "ST BOTOLPH BISHOPSGATE")
labvalch3, subst("ST. GILES WITHOUT CRIPPLEGATE" "ST GILES CRIPPLEGATE")
labvalch3, subst("ST BOTOLPH WITHOUT ALDERSGATE" "ST BOTOLPH ALDERSGATE")
labvalch3, subst("ST. SEPULCHRE WITHOUT NEWGATE" "ST SEPULCHRE")
labvalch3, subst("ST. ANDREW HOLBORN BELOW THE BARS" "ST ANDREW HOLBORN")
labvalch3, subst("BARNARDS INN" "BARNARD'S INN")
labvalch3, subst("SERJEANTS INN" "SARJEANT'S INN")
labvalch3, subst("BRIDEWELL PRECINCT" "PRECINCT OF BRIDEWELLL")
labvalch3, subst("WHITEFRIARS PRECINCT" "PRECINCT OF WHITEFRIARS")
labvalch3, subst("ST BENET PAULS WHARF" "ST BENET PAUL'S WHARF")
labvalch3, subst("ST PETHER PAULS WHARF" "ST PETER PAUL'S WHARF")
labvalch3, subst("ST MARY MAGDALEN OLD FISH STREET" "ST MARY MAGDALEN BERMONDSEY OLD FISH STREET")
labvalch3, subst("ST. PANCRAS SOPER LANE" "ST PANCRAS SOPER LANE")
labvalch3, subst("ST GREGORY BY ST PAUL" "ST GREGORY BY ST PAUL'S")
labvalch3, subst("ST AUGUSTINE (WATLING STREET)" "ST AUGUSTINE")
labvalch3, subst("ST FAITH UNDER ST PAULS" "ST FAITH UNDER ST PAUL'S")
labvalch3, subst("CHRISTCHURCH (NEWGATE)" "CHRIST CHURCH")
labvalch3, subst("ST VEDAST" "ST VEDAST FOSTER")
labvalch3, subst("ST ALBAN WOOD STREET" "ST ALBAN")
labvalch3, subst("ST MARTIN POMROY" "ST MARTIN POMARY")
labvalch3, subst("ALLHALLOWS BREAD STREET" "ALL HALLOWS BREAD STREET")
labvalch3, subst("ST JAMES GARLICKHITHE" "ST JAMES GARLICK")
labvalch3, subst("ST STEPHEN WALBROOK" "ST STEPHEN WALBR")
labvalch3, subst("ALLHALLOWS THE GREAT" "ALL HALLOWS THE GREAT")
labvalch3, subst("ALLHALLOWS THE LESS" "ALL HALLOWS THE LESS")
labvalch3, subst("ST LAWRENCE POUNTNEY" "ST LAURENCE POUNTNEY")
labvalch3, subst("ST MARTIN ORGARS" "ST MARTIN ORGAR")
labvalch3, subst("ST MARGARET NEW FISH STREET" "ST MARGARET FISH")
labvalch3, subst("ST ANDREW HUBBARD" "ST ANDREW HUBBAR")
labvalch3, subst("ALLHALLOWS BARKING" "ALL HALLOWS BARKING")
labvalch3, subst("ST OLAVE HART STREETN THE SHAMBLES" "ST OLAVE HART STREET")
labvalch3, subst("ST KATHARINE COLEMAN" "ST KATHERINE COLEMAN STREET")
labvalch3, subst("ALLHALLOWS STAINING" "ALL HALLOWS STAINING")
labvalch3, subst("ST GABRIEL FENCHURCH" "STREET ST GABRIEL FENCHURCH")
labvalch3, subst("ST LEONARD EASTCHEAP" "ST LEONARD EASTC")
labvalch3, subst("ST PETER CORNHILL" "ST PETER CORNHIL")
labvalch3, subst("ST BARTHOLOMEW BY THE EXCHANGE" "ST BATHOLOMEW BY THE EXCHANGE")
labvalch3, subst("ALLHALLOWS LONDON WALL" "ALL HALLOWS LONDON WALL")
labvalch3, subst("ST HELEN BISHOPSGATE" "ST HELEN")
labvalch3, subst("ST KATHERINE CREE" "ST KATHERINE CREECHURCH")
labvalch3, subst("ST JAMES DUKES PLACE" "ST JAMES DUKE STREET")
labvalch3, subst("THE ROLLS" "LIBERTY OF THE ROLLS")
labvalch3, subst("SPITALFIELDS" "CHRISTCHURCH SPITALFIELDS")
labvalch3, subst("ST. GEORGE IN THE EAST" "ST GEORGE IN THE EAST")
labvalch3, subst("RATCLIFF" "RATCLIFFE")
labvalch3, subst("LIMEHOUSE" "ST ANNE LIMEHOUSE")
labvalch3, subst("BROMLEY" "BROMLEY ST LEONARD")
labvalch3, subst("CHRISTCHURCH, SOUTHWARK" "CHRISTCHURCH SOUTHWARK")
labvalch3, subst("ST. SAVIOUR SOUTHWARK" "ST SAVIOUR SOUTHWARK")
labvalch3, subst("ST. GEORGE THE MARTYR" "ST GEORGE THE MARTYR")
labvalch3, subst("SOUTHWARK ST. OLAVE" "ST OLAVE SOUTHWARK")
labvalch3, subst("SOUTHWARK ST. THOMAS" "ST THOMAS")
labvalch3, subst("ST. JOHN HORSLEYDOWN" "ST JOHN HORSELYDOWN")
labvalch3, subst("ST. PAUL DEPTFORD" "ST PAUL DEPTFORD")
labvalch3, subst("ST. NICHOLAS DEPTFORD" "ST NICHOLAS DEPTFORD")
labvalch3, subst("ST MARY COLECHURCH" "ST MARY COLECHURH")
labvalch3, subst("ST PETHER PAULS WHARF" "ST PETER PAUL'S WHARF")
labvalch3, subst("NORTON FOLGATE" "LIBERTY OF NORTON FOLGATE")
labvalch3, subst("ST GILES IN THE FIELDSOMSBURY" "ST GILES IN THE FIELDS")
labvalch3, subst("ST MARTIN ORGARS" "ST MARTIN ORGAR")
labvalch3, subst("ST. MARGARET AND ST. JOHN WESTMINSTER" "ST MARGARET WESTMINSTER")
labvalch3, subst("ST. MARGARET AND ST. JOHN WESTMINSTER" "ST JOHN THE EVANGELIST WESTMINSTER")
labvalch3, subst("ST. ANDREW HOLBORN ABOVE THE BARS WITH" "ST ANDREW HOLBORN")
labvalch3, subst("CLERKENWELL" "ST JAMES CLERKENWELL")
labvalch3, subst("LAMBETH" "ST MARY LAMBETH")
labvalch3, subst("ST. LUKE" "ST LUKE OLD STREET")
labvalch3, subst("BETHNAL GREEN" "ST MATTHEW BETHNAL GREEN")
labvalch3, subst("WHITECHAPEL" "ST MARY WHITECHAPEL")
labvalch3, subst("PADDINGTON" "ST MARY PADDINGTON")
labvalch3, subst("BERMONDSEY" "ST MARY MAGDALEN BERMONDSEY")
labvalch3, subst("ST ANN AND ST AGNES ALDERSGATE" "ST ANNE AND ST AGNES")
labvalch3, subst("SHOREDITCH" "ST LEONARD SHOREDITCH")
labvalch3, subst("MILE END OLD TOWN" "ST DUNSTAN STEPNEY/MILE END")
labvalch3, subst("GLASSHOUSE YARD" "LIBERTY OF GLASSHOUSE YARD")
labvalch3, subst("SAFFRON HILL HATTON GARDEN ELY RENTS AN" "LIBERTY OF SAFFRON HILL")
labvalch3, subst("KENSINGTON" "ST MARY ABBOTS KENSINGTON")
labvalch3, subst("BOW AKA NYMET-TRACEY" "BOW")
labvalch3, subst("BOW AKA ST MARY STRATFORD-LE-BOW" "BOW")
labvalch3, subst("OLD TOWER WITHOUT AND TOWER OF LONDON" "LIBERTY OF THE OLD TOWER")
labvalch3, subst("ST KATHARINE BY THE TOWER" "PRECINCT OF ST KATHERINE")
labvalch3, subst("TOWER OF LONDON" "THE TOWER")
labvalch3, subst("OLD TOWER WITHOUT" "OLD TOWER WITHOUT AND TOWER OF LONDON")
labvalch3, subst("ROTHERHITHE" "ST MARY ROTHERHITHE")
labvalch3, subst("ST MARY MAGDALEN ST MARY MAGDALEN BERMONDSEY OLD FISH STREET" "ST MARY MAGDALEN BERMONDSEY OLD FISH STREET")

// 5. Name in MOLA is in string; parishgb is numerical

decode PARIDGB, gen(name)

replace name="THE TEMPLE" if name=="INNER TEMPLE"
replace name="THE TEMPLE" if name=="MIDDLE TEMPLE"
replace name="LIBERTY OF SAFFRON HILL" if name=="LIBERTY OF SAFFRON HILLD ELY PLACE"
replace name="ST GEORGE BLOOMSBURY" if name=="ST ANDREW HOLBORN GEORGE THE MARTYR"
replace name="ST BOTOLPH ALDGATE" if name=="ST BOTOLPH ALDGATE AKA EAST SMITHFIELD" 
replace name="ST LUKE CHELSEA" if name=="CHELSEA" 
replace name="ST SEPULCHRE" if name=="ST SEPULCHRE WITHOUT NEWGATE"
replace name="ST GABRIEL FENCHURCH" if name=="STREET ST GABRIEL FENCHURCH STREET" 
replace name="WESTMINSTER ABBEY" if name=="THE CLOSE OF THE COLLEGIATE CHURCH OF ST PETER"

save "$NAPP/NAPP_London3V1.dta", replace

